package org.jix.framework.biz.context.interceptor;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.jix.framework.biz.context.holder.LoginUserContextHolder;
import org.jix.framework.common.constant.GlobalConstants;

import java.util.Objects;

/**
 * @author stark
 * @date 2025/7/12 14:40
 * @description
 **/

@Slf4j
public class FeignRequestInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        //获取当前上下文中登录的用户id
        Long userID = LoginUserContextHolder.getUserID();

        //判空
        if (Objects.nonNull(userID)) {
            requestTemplate.header(GlobalConstants.USER_ID,String.valueOf(userID));
            log.info("########## feign 请求设置请求头 userId: {}", userID);
        }
    }
}
